package com.wyp168.serviceedu.controller;


import com.wyp168.commonutils.R;
import com.wyp168.serviceedu.entity.EduChapter;
import com.wyp168.serviceedu.entity.chapter.ChapterVo;
import com.wyp168.serviceedu.service.EduChapterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author wyp168
 * @since 2022-05-04
 */
@Api(tags = "章节控制器")
@RestController
@CrossOrigin
@RequestMapping("/serviceedu/edu-chapter")
public class EduChapterController {

    @Autowired
    private EduChapterService chapterService;


    //课程大纲列表
    @ApiOperation("根据课程id显示章节和小结内容")
    @GetMapping("getChapterVideo/{courseId}")
    public R getChapterVideo(@ApiParam("课程ID") @PathVariable String courseId) {
        List<ChapterVo> list = chapterService.getChapterVideoByCourseId(courseId);
        return R.ok().data("allChapterVideo",list);
    }

    //添加章节
    @PostMapping("addChapter")
    public R addChapter(
            @ApiParam("章节对象") @RequestBody EduChapter eduChapter
    ) {
        chapterService.save(eduChapter);

        return R.ok();
    }

    //根据章节id查询章节信息
    @GetMapping("getChapter/{chapterId}")
    public R getChapter(
            @ApiParam("章节id") @PathVariable String chapterId
    ) {
        EduChapter chapter = chapterService.getById(chapterId);
        return R.ok().data("chapter",chapter);
    }

    //修改章节
    @PostMapping("updateChapter")
    public R updateChapter(
            @ApiParam("章节对象") @RequestBody EduChapter eduChapter
    ) {
        chapterService.updateById(eduChapter);

        return R.ok();
    }

    //删除章节
    @DeleteMapping("deleteChapter/{chapterId}")
    public R deleteChapter(
        @ApiParam("章节Id") @PathVariable String chapterId
    ) {
        chapterService.deleteChapterById(chapterId);

        return R.ok();
    }
}




